package org.csmzxy.class2333;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
public class Example03 {
    public static void main(String[] args) throws Exception {
        // 创建Callable线程任务对象
        Callable<String> call01 = new MyCallable01();
        Callable<String> call02 = new MyCallable01();
        // 通过FutureTask对象封装Callable对象
        FutureTask<String> f1 = new FutureTask<>(call01);
        FutureTask<String> f2 = new FutureTask<>(call02);
        // 创建线程对象
        Thread t1 = new Thread(f1, "线程1");
        Thread t2 = new Thread(f2, "线程2");
        // 启动线程
        t1.start();
        t2.start();
        while (true) {
            if (f1.isDone()) {
                System.out.println(f1.get());
            }
            if (f2.isDone()) {
                System.out.println(f2.get());
            }
            System.out.println("main()");
            Thread.sleep(1000);
        }
    }
}